// RasterKey.h
//
#if 0
#include "RasterKey.h"

#include <QGraphicsScene>
#include "MemCheck.h"

using namespace IDS::IDEAS::OpenGLView::GUIElements;

//----------------------------------------------------------------------------------------------
RasterKey::RasterKey(int x, int y)
: GUIElement(0,0)
{
	setFlag(QGraphicsItem::ItemIsMovable,    true);
	setFlag(QGraphicsItem::ItemIsSelectable, true);
	setFlag(QGraphicsItem::ItemIsFocusable,  true);
	setAcceptHoverEvents(true);

	rect  = QRect(0,0,0,0);
	title = "";
}

//----------------------------------------------------------------------------------------------
RasterKey::~RasterKey() 
{}

//----------------------------------------------------------------------------------------------
void RasterKey::setValues( const std::vector< std::pair<double,double> > &values)
{
	if( values.size() < 2 )
		return;

	for(size_t i=0; i<values.size(); ++i)
	{
		QString txt("");	
		
		if( i > 0 && i < values.size()-1 )
			txt = QString("] %1 : %d ]").arg(values[i].first,0,'f',4).arg(values[i].second,0,'f',4);
		else
		{
			if( i == 0 && values[i].first == -std::numeric_limits<double>::infinity() )
				txt = QString("< %1").arg(values[i].second,0,'f',4);

			if( i == values.size()-1 && values[values.size()-1].second ==  std::numeric_limits<double>::infinity() )
				txt = QString(">= %1").arg(values[i].first,0,'f',4);
		}

		textItems.push_back( QGraphicsSimpleTextItem(txt) );
	}
	
	adjustRect();
}

//----------------------------------------------------------------------------------------------
void RasterKey::setColors( const std::vector< IDS::OpenGL::Color > &colors)
{
	adjustRect();
}

//-------------------------------------------------------------------------------------------------
void RasterKey::setTitle(const std::string &t)
{
	title = QObject::tr( t.c_str() );
	adjustRect();
}

//-------------------------------------------------------------------------------------------------
void RasterKey::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	if( title.length() == 0 )
		return;

	painter->setRenderHint(QPainter::Antialiasing,          true);
	painter->setRenderHint(QPainter::TextAntialiasing,      true);
	painter->setRenderHint(QPainter::SmoothPixmapTransform, true);

	painter->drawRect(rect);

	QBrush b = painter->brush();
	painter->setBrush( QBrush(QColor(255,255,225), Qt::SolidPattern ) );	

	painter->drawRect(rect);
	
	
	painter->setBrush(b);
	painter->drawText(rect, text);

	painter->setRenderHint(QPainter::Antialiasing, false);
	painter->setRenderHint(QPainter::TextAntialiasing, false);
	painter->setRenderHint(QPainter::SmoothPixmapTransform, false);

	GUIElement::paint(painter, option, widget);
}
#endif